//
//  ServiceViewController.m
//  Hxcsfw
//
//  Created by qiysoft on 2017/12/6.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "ServiceViewController.h"
#import "VideoDetailViewController.h"
#import "WWebViewController.h"
#import "GifView.h"
#import "TakePhotoViewController.h"
#import "ServiceCell.h"
#define ServiceCellIndentifier @"ServiceCellIndentifier"
#import "StateCell.h"
#define StateCellIndentifier @"StateCellIndentifier"
#import "LoginViewController.h"
#import "MemberViewController.h"
#import "CheckNetwork.h"
#import "InvoiceViewController.h"
#import "ReportViewController.h"

@interface ServiceViewController ()<UITableViewDelegate,UITableViewDataSource,ServiceCellDelegate,StateCellDelegate>
{
    ServiceCell *cell1;
    //    StateCell *cell2;
    UIView *HView;
    UIView *viewContent;
    UIView *bgMebemView;
}
@property (nonatomic ,strong) NSString *UPSJ;//服务更新时间

@property (nonatomic ,strong) NSString *TITLE;//服务分享标题
@property (nonatomic ,strong) NSString *SUMMARY;//服务分享概要
@property (nonatomic ,strong) NSString *LINK;//服务分享地址
@property (nonatomic ,strong) NSString *IMG;//服务分享图片
@property (nonatomic, strong)StateCell *cell2;

@property (nonatomic ,strong) NSString *strId;//分享id
@property (nonatomic ,strong) NSString *strKhdupsj;//客户端更新时间
@property (nonatomic ,strong) NSString *strUpsj;//服务器更新时间

@end

@implementation ServiceViewController

#pragma mark 新版一键检测按钮
-(void)YJJC:(UIButton *)button {
    [WShareUtil setStatusBarBackgroundColor:[UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1]];

    _cell2.kpImage.hidden = YES;
    _cell2.sbImage.hidden = YES;
    _cell2.kpLabel.hidden = YES;
    _cell2.sbLabel.hidden = YES;
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    _cell2.StateLb.hidden = YES;
    _cell2.UpsjLb.hidden = YES;
    _cell2.TestingLb.hidden = NO;
    _cell2.YJJCBtn.hidden = YES;
    _cell2.FengeLb.hidden = YES;
    _cell2.FwShareBtn.hidden = YES;
    _cell2.shibaiLb.hidden = YES;
    _cell2.shibaiBtn.hidden = YES;
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];

    // 本地gif图片
    NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"999" ofType:@"gif"]];
    
    if (iPhone5SE) {
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(40+27.5, 100, WSCREENH_WIDTH-40*2, 55) data:localData];
        dataView.tag= 1000;
        
        [_cell2 addSubview:dataView];
    }else if (iPhone6Plus_6sPlus) {
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(50, 100, WSCREENH_WIDTH-70*2, 55) data:localData];
        dataView.tag= 1000;
        
        [_cell2 addSubview:dataView];
        
    }else if (XIPHONE) {//和iphone 375一样
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(65, 100, WSCREENH_WIDTH-65*2, 55) data:localData];
        dataView.tag= 1000;
        
        [_cell2 addSubview:dataView];
    } else if (iPhone6_6s) {
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(65, 100, WSCREENH_WIDTH-65*2, 55) data:localData];
        dataView.tag= 1000;
        
        [_cell2 addSubview:dataView];
    }else{
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(65+15, 100, WSCREENH_WIDTH-65*2+30, 55) data:localData];
        dataView.tag= 1000;
        
        [_cell2 addSubview:dataView];
    }
    
    [self YJJCDataRequest];
}

#pragma mark 新版服务分享
-(void)FwShare:(UIButton *)button {

    NSString *strUrl = [WShareUtil sharedData].shareLINK;

    NSString *theLast = [strUrl substringFromIndex:[strUrl length]-1];
    if (![theLast isEqualToString:@"?"]) {
        strUrl = [strUrl stringByAppendingString: @"?"];
    }
    
    WLog(@"服务分享");
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone)]];
    // --- 设置分享面板的UI
    [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = YES;//有无标题
    [UMSocialShareUIConfig shareInstance].shareCancelControlConfig.isShow = YES;//有无取消
    [UMSocialShareUIConfig shareInstance].shareTitleViewConfig.shareTitleViewTitleString = @"";//标题文字
    [UMSocialShareUIConfig shareInstance].shareCancelControlConfig.shareCancelControlText = @"取消";//取消文字
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxItemWidth = 50;//每页Items的最大宽度(白圈的大小)
    [UMSocialShareUIConfig shareInstance].sharePageScrollViewConfig.shareScrollViewPageMaxItemHeight = 90;//每页Items的最大高度(背景的高低)
    
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的1确定所选平台进行下一步操作
        
        /*
         详情
         */
        NSString *descrStr = [WShareUtil filterHTML:[WShareUtil sharedData].shareSUMMARY];
        descrStr = [descrStr stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];//去掉特殊符号
        descrStr = [descrStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];//去掉左右两端的空格
        /*
         图片
         */
        NSURL *imgUrl = [NSURL URLWithString:[WShareUtil sharedData].shareIMG];
        NSData *dateImg = [NSData dataWithContentsOfURL:imgUrl];
        
        if (dateImg == nil || dateImg.length <= 0) {
            UMShareWebpageObject *webO = [UMShareWebpageObject shareObjectWithTitle:[WShareUtil sharedData].shareTITLE descr:descrStr thumImage:[UIImage imageNamed:@"logo_share.png"]];
            webO.webpageUrl = [NSString stringWithFormat:@"%@&source=zst",strUrl];
            [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:[UMSocialMessageObject messageObjectWithMediaObject:webO] currentViewController:self completion:^(id result, NSError *error) {
                
                NSString *message = nil;
                if (!error) {
                    message = [NSString stringWithFormat:@"分享成功"];
                } else {
                    message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code];
                    
                }
            }];
        } else {
            UMShareWebpageObject *webO = [UMShareWebpageObject shareObjectWithTitle:[WShareUtil sharedData].shareTITLE descr:descrStr thumImage:dateImg];
            webO.webpageUrl = [NSString stringWithFormat:@"%@&source=zst",strUrl];
            [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:[UMSocialMessageObject messageObjectWithMediaObject:webO] currentViewController:self completion:^(id result, NSError *error) {
                
                NSString *message = nil;
                if (!error) {
                    message = [NSString stringWithFormat:@"分享成功"];
                } else {
                    message = [NSString stringWithFormat:@"失败原因Code: %d\n",(int)error.code];
                }
            }];
        }
    }];
}

-(void)SJPFWNOTICE {
    
    UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    TakePhotoViewController *takePhotoVc = [mainStory instantiateViewControllerWithIdentifier:@"TakePhotoViewController"];
    takePhotoVc.title = @"手机拍服务";
    [self.navigationController pushViewController:takePhotoVc animated:NO];
    
}

-(void)XHAZNOTICE {
    WWebViewController *webVc = [[WWebViewController alloc] init];
    webVc.strTitle = @"新户安装";
    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"fwyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
    [self.navigationController pushViewController:webVc animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SJPFWNOTICE) name:@"SJPFW" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(XHAZNOTICE) name:@"XHAZ" object:nil];

    _UPSJ = [NSString string];
    _TITLE = [NSString string];
    _SUMMARY = [NSString string];
    _LINK = [NSString string];
    _IMG = [NSString string];
    
//    [self GetShareInfo];//获取分享信息
    
    // 1.注册控件
    UINib *cellNib = [UINib nibWithNibName:@"ServiceCell" bundle:nil];
    [self.myTableView registerNib:cellNib forCellReuseIdentifier:ServiceCellIndentifier];
    _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _myTableView.bounces = NO;
    self.prototypeCell  = [self.myTableView dequeueReusableCellWithIdentifier:ServiceCellIndentifier];
    
    _cell2 = [[[NSBundle mainBundle] loadNibNamed:@"StateCell" owner:self options:nil] lastObject];
    _cell2.delegate = self;
    
    _cell2.YJJCBtn.layer.masksToBounds = YES;
    _cell2.YJJCBtn.layer.cornerRadius = 13;
    _cell2.kpImage.userInteractionEnabled = NO;
    _cell2.sbImage.userInteractionEnabled = NO;
    _cell2.StateLb.hidden = NO;
    _cell2.kpImage.hidden = YES;
    _cell2.sbImage.hidden = YES;
    _cell2.kpLabel.hidden = YES;
    _cell2.sbLabel.hidden = YES;
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    
    HView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, 200)];
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];
    
    if (iPhone5SE) {
        _cell2.frame = CGRectMake(-27.5, 0, 375, 200);
        _cell2.shareYou.constant = 30;
        _cell2.shareTitleZuo.constant = 50;
        _cell2.upsjLbZuo.constant = 50;
    }else if (iPhone6_6s) {
        _cell2.frame = CGRectMake(0, 0, 375, 200);
        _cell2.shareTitleZuo.constant = 50;
        _cell2.upsjLbZuo.constant = 50;
        _cell2.JianCeBtnZuo.constant = 22;
    }else if (iPhone6Plus_6sPlus) {
        _cell2.frame = CGRectMake(19.5, 0, 375, 200);
        _cell2.shareYou.constant = 0;
        _cell2.shareTitleZuo.constant = 53;
        _cell2.upsjLbZuo.constant = 53;
        _cell2.JianCeBtnZuo.constant = 23;

    }else if (XIPHONE) {
        _cell2.frame = CGRectMake(0, 0, 375, 200);
        _cell2.shareTitleZuo.constant = 53;
        _cell2.upsjLbZuo.constant = 53;
        _cell2.JianCeBtnZuo.constant = 22;

    }else {
        _cell2.frame = CGRectMake(-30, 0, 375, 200);
        _cell2.shareTitleZuo.constant = 55;
        _cell2.upsjLbZuo.constant = 60;
        _cell2.JianCeBtnZuo.constant = 22;
        _cell2.shareYou.constant = 15;
    }
    
    [HView addSubview:_cell2];
    self.myTableView.tableHeaderView = HView;
    [self.myTableView.superview insertSubview:[UIView new] atIndex:0];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    [WShareUtil setStatusBarBackgroundColor:[UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1]];

    // 如果全局DicState为空（首页没把服务器状态检测出来并保存）
    if ([[WShareUtil sharedData].DicState isKindOfClass:[NSNull class]]||[[WShareUtil sharedData].DicState isEqual:[NSNull null]]||[WShareUtil sharedData].DicState == nil) {
        [self YJJC:_cell2.YJJCBtn];//检测
//        [self timerActionE];//直接设置失败

    }else {//不为空直接拿来显示
        WLog(@"单例字典%@",[WShareUtil sharedData].DicState);
        
        if([[WShareUtil sharedData].DicState[@"status"] isEqualToString:@"0"]){
            [self timerActionA];
            
        }else if([[WShareUtil sharedData].DicState[@"status"] isEqualToString:@"1"]){
            [self timerActionB];

        }else if([[WShareUtil sharedData].DicState[@"status"] isEqualToString:@"2"]){
            [self timerActionC];

        }else if([[WShareUtil sharedData].DicState[@"status"] isEqualToString:@"3"]){
            [self timerActionD];

        }else if([[WShareUtil sharedData].DicState[@"status"] isEqualToString:@"4"]){
            [self timerActionE];
        }else{
            [self timerActionE];
        }
        
        _UPSJ = [WShareUtil sharedData].DicState[@"khdupsj"];
        _cell2.UpsjLb.text = [NSString stringWithFormat:@"%@更新",_UPSJ];

    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [WShareUtil setStatusBarBackgroundColor:[UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1]];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [WShareUtil setStatusBarBackgroundColor:[UIColor clearColor]];
}

//设置UITableViewCell的数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    cell1  = [[[NSBundle mainBundle] loadNibNamed:@"ServiceCell" owner:self options:nil] lastObject];
    cell1.selectionStyle = UITableViewCellSelectionStyleNone;//点击不变色
    cell1.delegate = self;
    return cell1;
}

//行点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}

//分组个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//列表行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

//设置行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat height = 0;
    if (iPhone5SE) {
        height = 598;
    }else if (iPhone6_6s) {
        height = 618;
    }else if (iPhone6Plus_6sPlus) {
        height = 648;
    }else if (XIPHONE) {
        height = 628;
    }else {
        height = 608;
    }
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, 1)];
    headerView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    return headerView;
}

- (void)servicedelegatBtnClick:(UIButton *)button {
    if (button.tag == 1111) {
        //开票
        InvoiceViewController *invoiceVc = [[InvoiceViewController alloc] init];
        invoiceVc.title = @"税控开票";
        [self.navigationController pushViewController:invoiceVc animated:YES];

        /* 手机拍服务暂时去掉
         if ([WShareUtil sharedData].dicSession) {

         UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
         TakePhotoViewController *takePhotoVc = [mainStory instantiateViewControllerWithIdentifier:@"TakePhotoViewController"];
         takePhotoVc.title = @"手机拍服务";
         [self.navigationController pushViewController:takePhotoVc animated:YES];

         }else {
         //        [SVProgressHUD showImage:nil status:@"请先登录"];
         //        [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
         //        [SVProgressHUD dismissWithDelay:1.];
         //        [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];

         [WShareUtil sharedData].Who = @"SJPFW";
         LoginViewController *loginVc = [[LoginViewController alloc] init];
         [self.navigationController pushViewController:loginVc animated:YES];
         }
         */
        //    [self openMemberSheet];

        //    WWebViewController *webVc = [[WWebViewController alloc] init];
        //    webVc.strTitle = @"在线客服";
        //    webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
        //    [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 1001) {
        //网上申报
        ReportViewController *reportVc = [[ReportViewController alloc] init];
        reportVc.title = @"网上申报";
        [self.navigationController pushViewController:reportVc animated:YES];

    }else if (button.tag == 1002) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"故障修复";
        webVc.shareTitle = @"故障修复";//分享标题
        webVc.from = @"gzxf";//来源
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhO0IohySyfFK8zWhtAEUA%2B8";
        [self.navigationController pushViewController:webVc animated:YES];

    }else if (button.tag == 1003) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"征期清卡";
        webVc.shareTitle = @"征期清卡";//分享标题
        webVc.from = @"zqqk";//来源
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhMGUMsXchv6yPFw906k8tzz";
        [self.navigationController pushViewController:webVc animated:YES];

    }else if (button.tag == 1004) {

//        会员缴费
        CheckNetwork *checkNetwork = [[CheckNetwork alloc] init];
        if (![checkNetwork isNetworkReachable]) {//没网
            return;
        } else {

            if ([WShareUtil strNilOrEmpty:[WShareUtil sharedData].strlxmc]) {
                MemberViewController *memberVc = [[MemberViewController alloc] init];
                memberVc.title = @"会员缴费";
                [self.navigationController pushViewController:memberVc animated:YES];
            } else {
                NSString *message = [NSString stringWithFormat:@"您已经是%@",[WShareUtil sharedData].strlxmc];
                [WShareUtil showAlert:ALERT_TITLE message:message];
            }
//            [self requestWdjf];
        }
        //    WWebViewController *webVc = [[WWebViewController alloc] init];
        //    /*
        //    webVc.strTitle = @"开票升级";
        //    webVc.shareTitle = @"开票升级";//分享标题
        //    webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUZBwRlJP27O9jCsqyZ%2Blitn1bcoNID6n7FfWzQbhPkQaPReG1sA1bDXu41AP7nlBDz%0D%0ADENLDn494%2BsKj%2Bhbo%2BmE3%2FqTHWk28UT5oWpzxbhCZPyi%2B4UFPDwJ";
        //     */
        //    webVc.strTitle = @"办税日历";
        //    webVc.shareTitle = @"办税日历";//分享标题
        //    webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUZBwRlJP27O5Xv23wUOf%2FqkA5c8xi3MaoMTs5%2BjpCPT1M9cHFSt7skYkaNuWT%2BEhND%0D%0AtX0XRVPc8uIsFGQ3LwNS";
        //    [self.navigationController pushViewController:webVc animated:YES];

        //办税日历改成了网上缴费，又改成了会员缴费，又改成了办税日历


    }else if (button.tag == 1005) {

        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"办税日历";
        webVc.shareTitle = @"办税日历";//分享标题
        webVc.strID = @"41063";//分享ID
        webVc.strType = @"sx";//分享类型税信
        webVc.from = @"bsrl";//来源
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUZBwRlJP27O5Xv23wUOf%2FqkA5c8xi3MaoMTs5%2BjpCPT1M9cHFSt7skYkaNuWT%2BEhND%0D%0AtX0XRVPc8uIsFGQ3LwNS";
        [self.navigationController pushViewController:webVc animated:YES];

    }else if (button.tag == 1006) {

        if ([WShareUtil sharedData].dicSession) {
            WWebViewController *webVc = [[WWebViewController alloc] init];
            webVc.strTitle = @"新户安装";
            NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"fwyy",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
            NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
            webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
            [self.navigationController pushViewController:webVc animated:YES];

        } else {
            [WShareUtil sharedData].Who = @"XHAZ";
            LoginViewController *loginVc = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVc animated:YES];
        }
//        WWebViewController *webVc = [[WWebViewController alloc] init];
//        webVc.strTitle = @"服务助手";
//        webVc.shareTitle = @"服务助手";//分享标题
//        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhN96DAUcETN9nPIYHd3ozja";
//        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 1007) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"95113服务网";
        webVc.strUrl = @"http://www.sx95113.com";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2000) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"财税培训";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dCpqRTSS3TUtETXxUe4JzQNoBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2001) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"财税咨询";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dPmpKuTbXI1IlKYfiZTrZNhoBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2002) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"财税门诊";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dPmpKuTbXI1ITSoVJj7vldBoBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2003) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"风险检测";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dCpqRTSS3TUtIRKOda%2Fh94JoBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2004) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"会员期刊";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dLW6vT2dv%2BMV112CS%2FqIR4toBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 2005) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"技术服务";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BUifg3qsfo4dDAOnRCbW5WT959Sz5pZGcVoBnfSMhFfc0kFsKlyzzdM29ztsJRQK6mz%0D%0ACbDJyYwzlA%3D%3D";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 3000) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"财税通会员专区";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhOc5kkLGkbiN4K%2BYqUhOGeU";
        [self.navigationController pushViewController:webVc animated:YES];
    }else if (button.tag == 3001) {
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"易税通会员专区";
        webVc.strUrl = @"http://www.sx95113.com/zstapp?params=%2FO5VEuP53%2BWqeopc9K5F1VM9cHFSt7skYkaNuWT%2BEhPi8llkHpX22oK%2BYqUhOGeU";
        [self.navigationController pushViewController:webVc animated:YES];
    }
}

- (IBAction)ksjcBtn:(id)sender {
    
    _ksjcBtn.hidden = YES;
    _kpImage.hidden = YES;
    _sbImage.hidden = YES;
    _kpLabel.hidden = YES;
    _sbLabel.hidden = YES;
    _kaishiView.hidden = YES;
    _bottomLabel.hidden = NO;
    _bottomLabel.text = @"报税网络检测中...";
    _ShiBaiView.hidden = YES;
    _ShiBaiImage.hidden = YES;
    _ShiBaiLabel.hidden = YES;
    
    // 本地gif图片
    NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"999" ofType:@"gif"]];
    
    if (iPhone5SE) {
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(40, 90, WSCREENH_WIDTH-40*2, 55) data:localData];
        dataView.tag= 1000;
        
        [self.view addSubview:dataView];
    }else if (iPhone6Plus_6sPlus) {
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(70, 110, WSCREENH_WIDTH-70*2, 60) data:localData];
        dataView.tag= 1000;
        
        [self.view addSubview:dataView];
        
    }else{
        GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(65, 90, WSCREENH_WIDTH-65*2, 55) data:localData];
        dataView.tag= 1000;
        
        [self.view addSubview:dataView];
    }
    
    
    [self YJJCDataRequest];//这个新版没用到别管
    
}

#pragma mark - 一键检测网络请求
- (void)YJJCDataRequest {
    /*
     mode:native,service:init,content:{screen:server}
     */
    [WShareUtil sharedData].isShowWait = YES;
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"screen":@"server"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
    
    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];

        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        [WShareUtil sharedData].DicState = (NSMutableDictionary *)returnDic; //服务器状态保存到全局单例(服务页检测完再存一次)
        
        //请求成功先给参数赋值，再调分享接口
        _strId = returnDic[@"id"];
        _strKhdupsj = returnDic[@"khdupsj"];
        _strUpsj = returnDic[@"upsj"];
        
        [self GetShareInfo];//获取分享信息

        if([returnDic[@"status"] isEqualToString:@"0"]){
            
            [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionA) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"1"]){
            
            [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionB) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"2"]){
            [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionC) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"3"]){
            [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionD) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"4"]){
//            [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];
            [self timerActionE];
        }
        _UPSJ = returnDic[@"khdupsj"];
        _cell2.UpsjLb.text = [NSString stringWithFormat:@"%@更新",_UPSJ];
        
    } failure:^(NSError *error) {
        WLog(@"失败");
//        [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];
        [self timerActionE];

    } showProgress:YES];
}

- (void)timerActionA {//开票、申报服务器正常
    
    UIView *bgView = [self.view viewWithTag:1000];
    [bgView removeFromSuperview];
    
    _cell2.StateLb.text = @"报税服务器状态";
    _cell2.kpImage.hidden = NO;
    _cell2.sbImage.hidden = NO;
    _cell2.kpLabel.hidden = NO;
    _cell2.sbLabel.hidden = NO;
    _cell2.StateLb.hidden = NO;
    _cell2.UpsjLb.hidden = NO;
    _cell2.TestingLb.hidden = YES;
    _cell2.YJJCBtn.hidden = NO;
    _cell2.FengeLb.hidden = NO;
    _cell2.FwShareBtn.hidden = NO;
    _cell2.sbLabel.text = @"申报服务器正常";
    [_cell2.kpImage setImage:[UIImage imageNamed:@"fw_22"] forState:UIControlStateNormal];
    [_cell2.sbImage setImage:[UIImage imageNamed:@"fw_22"] forState:UIControlStateNormal];
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];
    _cell2.shibaiLb.hidden = YES;
    _cell2.shibaiBtn.hidden = YES;
}
- (void)timerActionB {//开票服务器异常,申报服务器正常
    
    UIView *bgView = [self.view viewWithTag:1000];
    [bgView removeFromSuperview];
    
    _cell2.StateLb.text = @"报税服务器状态";
    _cell2.kpImage.hidden = NO;
    _cell2.sbImage.hidden = NO;
    _cell2.kpLabel.hidden = NO;
    _cell2.sbLabel.hidden = NO;
    _cell2.StateLb.hidden = NO;
    _cell2.UpsjLb.hidden = NO;
    _cell2.TestingLb.hidden = YES;
    _cell2.YJJCBtn.hidden = NO;
    _cell2.FengeLb.hidden = NO;
    _cell2.FwShareBtn.hidden = NO;
    _cell2.kpLabel.text = @"开票服务器异常";
    _cell2.sbLabel.text = @"申报服务器正常";
    [_cell2.kpImage setImage:[UIImage imageNamed:@"fw_23"] forState:UIControlStateNormal];
    [_cell2.sbImage setImage:[UIImage imageNamed:@"fw_22"] forState:UIControlStateNormal];
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];
    _cell2.shibaiLb.hidden = YES;
    _cell2.shibaiBtn.hidden = YES;
}

- (void)timerActionC {//申报服务器异常,开票服务器正常
    
    UIView *bgView = [self.view viewWithTag:1000];
    [bgView removeFromSuperview];
    
    _cell2.StateLb.text = @"报税服务器状态";
    _cell2.kpImage.hidden = NO;
    _cell2.sbImage.hidden = NO;
    _cell2.kpLabel.hidden = NO;
    _cell2.sbLabel.hidden = NO;
    _cell2.StateLb.hidden = NO;
    _cell2.UpsjLb.hidden = NO;
    _cell2.YJJCBtn.hidden = NO;
    _cell2.FengeLb.hidden = NO;
    _cell2.FwShareBtn.hidden = NO;
    _cell2.TestingLb.hidden = YES;
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    [_cell2.kpImage setImage:[UIImage imageNamed:@"fw_22"] forState:UIControlStateNormal];
    [_cell2.sbImage setImage:[UIImage imageNamed:@"fw_23"] forState:UIControlStateNormal];
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];
    _cell2.shibaiLb.hidden = YES;
    _cell2.shibaiBtn.hidden = YES;
}

- (void)timerActionD {//开票、申报服务器异常
    UIView *bgView = [self.view viewWithTag:1000];
    [bgView removeFromSuperview];
    
    _cell2.StateLb.text = @"报税服务器状态";
    _cell2.kpImage.hidden = NO;
    _cell2.sbImage.hidden = NO;
    _cell2.kpLabel.hidden = NO;
    _cell2.sbLabel.hidden = NO;
    _cell2.StateLb.hidden = NO;
    _cell2.UpsjLb.hidden = NO;
    _cell2.YJJCBtn.hidden = NO;
    _cell2.FengeLb.hidden = NO;
    _cell2.FwShareBtn.hidden = NO;
    _cell2.TestingLb.hidden = YES;
    _cell2.kpLabel.text = @"开票服务器异常";
    [_cell2.kpImage setImage:[UIImage imageNamed:@"fw_23"] forState:UIControlStateNormal];
    [_cell2.sbImage setImage:[UIImage imageNamed:@"fw_23"] forState:UIControlStateNormal];
    _cell2.ShiBaiView.hidden = YES;
    _cell2.ShiBaiImage.hidden = YES;
    HView.backgroundColor = [UIColor colorWithRed:0.24 green:0.36 blue:0.96 alpha:1];
    _cell2.shibaiLb.hidden = YES;
    _cell2.shibaiBtn.hidden = YES;
}
- (void)timerActionE {//获取失败
    
    if (self.isViewLoaded && self.view.window) {
        WLog(@"ServiceVC在当前屏幕上,设黄");
        [WShareUtil setStatusBarBackgroundColor:[UIColor colorWithRed:0.91 green:0.57 blue:0.08 alpha:1]];
    }else {
        WLog(@"ServiceVC不在当前屏幕上，不设黄");
    }
    UIView *bgView = [self.view viewWithTag:1000];
    [bgView removeFromSuperview];
    
    _cell2.StateLb.text = @"服务器状态检测失败";
    _cell2.kpImage.hidden = YES;
    _cell2.sbImage.hidden = YES;
    _cell2.kpLabel.hidden = YES;
    _cell2.sbLabel.hidden = YES;
    _cell2.YJJCBtn.hidden = YES;
    _cell2.TestingLb.hidden = YES;
    _cell2.ShiBaiView.hidden = NO;
    _cell2.ShiBaiImage.hidden = NO;
    _cell2.FwShareBtn.hidden = YES;
    _cell2.StateLb.hidden = NO;
    _cell2.UpsjLb.hidden = YES;
    _cell2.shibaiLb.hidden = NO;
    _cell2.shibaiBtn.hidden = NO;
    _cell2.StateLb.hidden = YES;

    HView.backgroundColor = [UIColor colorWithRed:0.91 green:0.57 blue:0.08 alpha:1];

}

#pragma mark - 获取分享所需要的信息
- (void)GetShareInfo {

    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strId = @"";
    }
    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strKhdupsj = @"";
    }
    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strUpsj = @"";
    }

    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"shareinfo",@"content":@{@"id":_strId,@"timer":_strKhdupsj,@"nowtime":_strUpsj,@"type":@"server"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
    
    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        /*之前是给当前页的参数赋值，改后给全局单例参数赋值
        _TITLE = [returnDic objectForKey:@"title"];
        _SUMMARY = [returnDic objectForKey:@"summary"];
        _LINK = [returnDic objectForKey:@"link"];
        _IMG = [returnDic objectForKey:@"img"];
        */
        
        // 服务状态分享所需的字段
        [WShareUtil sharedData].shareTITLE = [returnDic objectForKey:@"title"];//分享标题
        [WShareUtil sharedData].shareSUMMARY = [returnDic objectForKey:@"summary"];//分享概要
        [WShareUtil sharedData].shareLINK = [returnDic objectForKey:@"link"];//分享地址
        [WShareUtil sharedData].shareIMG = [returnDic objectForKey:@"img"];//分享图片
        
    } failure:^(NSError *error) {
        WLog(@"失败");
        [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];
        
    } showProgress:NO];
}

- (void)openMemberSheet {
    
    bgMebemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT)];
    bgMebemView.backgroundColor = WRGBAColor(0, 0, 0, 0.5);
//    [self.view addSubview:bgMebemView];
    
    viewContent = [[UIView alloc] initWithFrame:CGRectMake((WSCREENH_WIDTH - 280) * 0.5, (WSCREENH_HEIGHT - 240) * 0.5, 280, 200)];
    viewContent.backgroundColor = WRGBColor(255, 255, 255);
    viewContent.layer.cornerRadius = 10;
    
    UILabel *lbTit = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, 280-30, 50)];
    lbTit.backgroundColor = [UIColor whiteColor];
    lbTit.text = @"请根据您要咨询的问题，选择对应的问题类型";
    lbTit.font = [UIFont systemFontOfSize:15];
    lbTit.textAlignment = NSTextAlignmentCenter;
    lbTit.numberOfLines = 0;
    [viewContent addSubview:lbTit];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 70, 280, 1)];
    lineView.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView];
    
    UIButton *btnMember = [[UIButton alloc] initWithFrame:CGRectMake(0, 70, 280, 44)];
    [btnMember.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnMember setTitle:@"防伪开票" forState:UIControlStateNormal];
    [btnMember setTitleColor:[UIColor colorWithRed:0 green:0.6 blue:0.92 alpha:1] forState:UIControlStateNormal];
    btnMember.tag = 100;
    [btnMember addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewContent addSubview:btnMember];
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 113, 280, 1)];
    lineView1.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView1];
    
    UIButton *btnTourist = [[UIButton alloc] initWithFrame:CGRectMake(0, 114, 280, 44)];
    [btnTourist.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnTourist setTitle:@"申报、认证等其他" forState:UIControlStateNormal];
    [btnTourist setTitleColor:[UIColor colorWithRed:0 green:0.6 blue:0.92 alpha:1] forState:UIControlStateNormal];
    btnTourist.tag = 110;
    [btnTourist addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    [viewContent addSubview:btnTourist];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 157, 280, 1)];
    lineView2.backgroundColor = WRGBColor(243, 243, 243);
    [viewContent addSubview:lineView2];
    
    UIButton *btnLogin = [[UIButton alloc] initWithFrame:CGRectMake(0, 158, 280, 44)];
    [btnLogin.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btnLogin setTitle:@"取消" forState:UIControlStateNormal];
    [btnLogin addTarget:self action:@selector(btnOpenClick:) forControlEvents:UIControlEventTouchUpInside];
    btnLogin.tag = 120;
    [btnLogin setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [viewContent addSubview:btnLogin];
    
    [bgMebemView addSubview:viewContent];
    [[[UIApplication sharedApplication] delegate].window addSubview:bgMebemView];

    
}

- (void)btnOpenClick:(UIButton *)btn {
    if (btn.tag == 100) {
        
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"开票客服";
        webVc.strUrl = @"http://www.sobot.com/chat/pc/index.html?sysNum=79f43fe7ebd049898175758d0b00d986";
        [self.navigationController pushViewController:webVc animated:YES];
        
    } else if (btn.tag == 110) {
       
        WWebViewController *webVc = [[WWebViewController alloc] init];
        webVc.strTitle = @"申报认证客服";
        webVc.strUrl = @"https://www.sobot.com/chat/h5/index.html?sysNum=f6a79964432e4eb1b2f70f92a6dfcbe4";
        [self.navigationController pushViewController:webVc animated:YES];
        
    } else {
        
    }
    [bgMebemView removeFromSuperview];
    [viewContent removeFromSuperview];
}

- (void)requestWdjf{

    NSDictionary *parametersDict;
    NSString *nologinuser;
    if ([WShareUtil sharedData].dicSession) {
        parametersDict = @{@"content":@{@"revert":@"basic",@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]},@"mode":@"native",@"service":@"mine"};
    } else {
        nologinuser = [WShareUtil getUUID];
        parametersDict = @{@"content":@{@"revert":@"basic",@"nologinuser":nologinuser},@"mode":@"native",@"service":@"mine"};
    }
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};


    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];

        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        if ([successStr isEqualToString:@"false"]) {
            [WShareUtil sharedData].strRemaining = @"0.0";
            return;
        }

        [WShareUtil sharedData].strRemaining = returnDic[@"remaining"];
        if ([WShareUtil strNilOrEmpty:returnDic[@"lxmc"]]) {
            MemberViewController *memberVc = [[MemberViewController alloc] init];
            memberVc.title = @"会员缴费";
            [self.navigationController pushViewController:memberVc animated:YES];
        } else {
            NSString *message = [NSString stringWithFormat:@"您已经是%@",returnDic[@"lxmc"]];
            [WShareUtil showAlert:ALERT_TITLE message:message];
        }
    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];
}

@end

